package com.chenfan.magic.service.impl;

import com.chenfan.common.vo.UserVO;
import com.chenfan.magic.config.UserVoConstextHolder;
import com.chenfan.magic.entity.IdcOperationLog;
import com.chenfan.magic.service.IdcOperationLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author liuming
 * @date 2021-11-04 14:28
 */
@Slf4j
@Service
public class LogService {

    @Autowired
    private IdcOperationLogService idcOperationLogService;

    /**
     * 记录日志
     */
    public void saveLog(String url) {
        UserVO userVo = UserVoConstextHolder.getUserVo();
        IdcOperationLog entity = new IdcOperationLog();
        entity.setUrl(url);
        entity.setCreateBy(userVo.getUserId());
        entity.setCreateName(userVo.getRealName());
        entity.setCreateTime(LocalDateTime.now());
        idcOperationLogService.save(entity);
    }
}
